home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-06-28 | 56.7 KB | 2,621 lines |
- Path: xanth!cs.odu.edu!Amiga-Request
- From: Amiga-Request@cs.odu.edu (Amiga Sources/Binaries Moderator)
- Newsgroups: comp.sources.amiga
- Subject: v90i183: UUCP 1.06D - UNIX compatible uucp/news/mail system, Part05/12
- Message-ID: <12974@xanth.cs.odu.edu>
- Date: 28 Jun 90 12:22:42 GMT
- Sender: news@cs.odu.edu
- Reply-To: Matt Dillon <@uunet.uu.net:overload!dillon>
- Lines: 2607
- Approved: tadguy@cs.odu.edu (Tad Guy)
- X-Mail-Submissions-To: Amiga@cs.odu.edu
- X-Post-Discussions-To: comp.sys.amiga
-
- Submitted-by: Matt Dillon <@uunet.uu.net:overload!dillon>
- Posting-number: Volume 90, Issue 183
- Archive-name: unix/uucp-1.06d/part05
-
- #!/bin/sh
- # This is a shell archive. Remove anything before this line, then unpack
- # it by saving it into a file and typing "sh file". To overwrite existing
- # files, type "sh file -c". You can also feed this as standard input via
- # unshar, or by typing "sh <file", e.g.. If this archive is complete, you
- # will see the following message at the end:
- # "End of archive 5 (of 12)."
- # Contents: uucp2/src/anews/mscan.c uucp2/src/anews/news.c
- # uucp2/src/anews/unpackmail.c uucp2/src/dmail/main.c
- # uucp2/src/dmail/sub.c uucp2/src/lib/alias.c
- # uucp2/src/news/postnews.c.OLD uucp2/src/sendmail/domain.c
- # uucp2/src/unix/unshar.c
- # Wrapped by tadguy@xanth on Thu Jun 28 08:21:24 1990
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- if test -f 'uucp2/src/anews/mscan.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'uucp2/src/anews/mscan.c'\"
- else
- echo shar: Extracting \"'uucp2/src/anews/mscan.c'\" \(5263 characters\)
- sed "s/^X//" >'uucp2/src/anews/mscan.c' <<'END_OF_FILE'
- X
- X/*
- X * MSCAN.C
- X *
- X * mscan - Scan directories and return a sorted list of file names,
- X * one at a time.
- X *
- X * This code originally taken from sysdep.c:
- X *
- X * (C) Copyright 1987 by John Gilmore
- X * Copying and use of this program are controlled by the terms of the Free
- X * Software Foundation's GNU Emacs General Public License.
- X *
- X * Amiga Changes Copyright 1988 by William Loftus. All rights reserved.
- X *
- X * Rewrite for nlib Copyright 1990 by J. Gregory Noel. All rights reserved.
- X */
- X
- X#include "news.h"
- X#include <ctype.h>
- X#include <getfiles.h>
- X#include <expand_path.h>
- X
- X#define GAP 2
- X
- Xextern char *NewsDir; /* Path to news directory */
- Xstatic dir_list *files; /* List of articles to be examined */
- Xstatic dir_list *curptr; /* Pointer to current article */
- Xstatic char *curgroup; /* Name of current group */
- X
- Xstatic int /* select only files that are purely numeric */
- Xfilesel(char *a)
- X{
- X while (*a != '\0') {
- X if (!isdigit(*a))
- X return 0;
- X ++a;
- X }
- X return 1;
- X}
- X
- Xstatic int /* sort based upon the numeric value of the filename */
- Xfilecmp(dir_list *a, dir_list *b)
- X{
- X register long i;
- X
- X i = atol(a->name + GAP) - atol(b->name + GAP);
- X if (i != 0) return i > 0;
- X return strcmp(a->name, b->name);
- X}
- X
- Xvoid /* remove files marked for deletion */
- Xfree_directory(delart)
- Xint delart;
- X{
- X register dir_list *p;
- X register int last;
- X
- X last = -1;
- X while (p = files) {
- X files = p->next;
- X if (p->name[0]) {
- X if (delart)
- X remove(expand_path(curgroup, p->name + GAP));
- X } else if (p->name[1])
- X last = atoi(p->name + GAP);
- X else if (last < 0)
- X last = 0;
- X free(p);
- X }
- X if (last >= 0) {
- X register FILE *fp;
- X if (fp = fopen(expand_path(curgroup, ".read"), "w")) {
- X fprintf(fp, "%d", last);
- X fclose(fp);
- X }
- X } else if (delart) {
- X /* all files were deleted -- try to delete directory */
- X remove(expand_path(curgroup, ".next"));
- X remove(expand_path(curgroup, ".read"));
- X rmdir(curgroup);
- X }
- X curptr = NULL;
- X if (curgroup) {
- X free(curgroup);
- X curgroup = NULL;
- X }
- X}
- X
- Xint /* produce a list of articles in the group */
- Xscan_directory(char *dir)
- X{
- X register dir_list *p;
- X register int count = 0;
- X register FILE *fp;
- X int read;
- X char name[100], newname[100];
- X extern int unpackmail(char *dir, int count);
- X
- Xrecurse:
- X free_directory(0);
- X curgroup = strdup((dir == NULL) ? NewsDir : expand_path(NewsDir, dir));
- X if (access(curgroup, 0) == -1) {
- X free(curgroup), curgroup = NULL;
- X return 0;
- X }
- X
- X if ((files = getfiles(curgroup, GAP, filesel, filecmp)) == NULL) {
- X if (unpackmail(curgroup, 0) > 0) {
- X /* return scan_directory(dir); */
- X goto recurse;
- X }
- X#ifdef NOTDEF /* DON'T DELETE THE !#@$#@ DIRECTORY IDIOT */
- X /* no files in directory -- try to delete directory */
- X remove(expand_path(curgroup, ".next"));
- X remove(expand_path(curgroup, ".read"));
- X rmdir(curgroup);
- X#endif
- X return 0;
- X }
- X
- X read = 0;
- X if ((fp = fopen(expand_path(curgroup, ".read"), "r")) != NULL) {
- X fscanf(fp, "%d", &read);
- X fclose(fp);
- X }
- X
- X for (p = files; p != NULL; p = p->next) {
- X p->name[0] = 0;
- X p->name[1] = (atoi(p->name + GAP) <= read);
- X sprintf(name, "%s/%s", curgroup, p->name + GAP);
- X sprintf(newname, "%s/%d", curgroup, ++count);
- X if (strcmp(name, newname) != 0)
- X if (rename(name, newname) == 0)
- X sprintf(p->name + GAP, "%d", count);
- X }
- X
- X if (unpackmail(curgroup, count) > count)
- X return scan_directory(dir);
- X
- X if ((fp = fopen(expand_path(curgroup, ".next"), "w")) != NULL) {
- X fprintf(fp, "%d", count + 1);
- X fclose(fp);
- X }
- X return count;
- X}
- X
- Xchar *
- Xfirst_unread(void)
- X{
- X register dir_list *p;
- X
- X for (p = files; p != NULL; p = p->next) {
- X if (p->name[1] == 0) {
- X curptr = p;
- X return p->name + GAP;
- X }
- X }
- X curptr = NULL;
- X return NULL;
- X}
- X
- Xint
- Xunread_count(void)
- X{
- X register dir_list *p;
- X register int count = 0;
- X
- X for (p = files; p != NULL; p = p->next)
- X if (p != curptr && p->name[1] == 0)
- X ++count;
- X return count;
- X}
- X
- Xchar *
- Xgoto_article(char *name)
- X{
- X register dir_list *p;
- X
- X for (p = files; p != NULL; p = p->next) {
- X if (strcmp(p->name + GAP, name) == 0) {
- X curptr = p;
- X return p->name + GAP;
- X }
- X }
- X curptr = NULL;
- X return NULL;
- X}
- X
- Xchar *
- Xget_next_art(void)
- X{
- X if (curptr == NULL)
- X curptr = files;
- X else
- X curptr = curptr->next;
- X return (curptr == NULL) ? NULL : curptr->name + GAP;
- X}
- X
- Xchar *
- Xget_prev_art(void)
- X{
- X register dir_list *p;
- X
- X if (curptr == NULL)
- X return NULL;
- X if (curptr == files)
- X return curptr->name + GAP;
- X for (p = files; p != NULL; p = p->next) {
- X if (p->next == curptr) {
- X curptr = p;
- X return p->name + GAP;
- X }
- X }
- X /* should never get here... */
- X curptr = NULL;
- X return NULL;
- X}
- X
- Xvoid
- Xrewind_arts(void)
- X{
- X register dir_list *p;
- X
- X for (p = files; p != NULL; p = p->next)
- X if (p->name[0] == 0)
- X p->name[1] = 0;
- X curptr = NULL;
- X}
- X
- Xvoid
- Xmark_cur_art(int flag)
- X{
- X if (curptr != NULL)
- X curptr->name[1] = flag;
- X}
- X
- Xvoid
- Xdel_cur_art(int flag)
- X{
- X if (curptr != NULL)
- X curptr->name[0] = flag;
- X}
- X
- Xvoid
- Xhold_cur_art(void)
- X{
- X if (curptr != NULL)
- X curptr->name[1] = curptr->name[0];
- X}
- X
- X#ifdef TEST
- X#undef TEST
- X#include "unpackmail.c"
- Xchar *NewsDir;
- X
- Xmain(int argc, char **argv)
- X{
- X register char *p;
- X
- X NewsDir = GetConfigDir(UUNEWS);
- X printf("%d articles:\n", scan_directory("mail.test"));
- X while ((p = get_next_art()) != NULL)
- X printf("%s ", p);
- X putchar('\n');
- X return 0;
- X}
- X#endif
- END_OF_FILE
- if test 5263 -ne `wc -c <'uucp2/src/anews/mscan.c'`; then
- echo shar: \"'uucp2/src/anews/mscan.c'\" unpacked with wrong size!
- fi
- # end of 'uucp2/src/anews/mscan.c'
- fi
- if test -f 'uucp2/src/anews/news.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'uucp2/src/anews/news.c'\"
- else
- echo shar: Extracting \"'uucp2/src/anews/news.c'\" \(6709 characters\)
- sed "s/^X//" >'uucp2/src/anews/news.c' <<'END_OF_FILE'
- X
- X/*
- X * ANEWS -r rows -c cols -p group
- X */
- X
- X#include "news.h"
- X#include <ctype.h>
- X#include <libraries/dos.h>
- X#include <getfiles.h>
- X
- XIDENT(".03");
- X
- X#define ON scr_inverse_on()
- X#define OFF scr_inverse_off()
- X#define Clear_eol printf("\x9bK")
- X#define Clear_Screen printf("\x9bH\x9bJ")
- X#define Cr putchar('\r')
- X#define PROG_NAME "Anews"
- X
- Xchar *NewsDir;
- Xchar fg, bg;
- X
- Xint NumRows = 22;
- Xint NumCols = 77;
- X
- Xdir_list *groups;
- X
- Xvoid
- Xinitgroups(void)
- X{
- X dir_list *gp;
- X int len;
- X FILE *fp;
- X char buf[50];
- X
- X if (groups != NULL)
- X return;
- X
- X if ((fp = openlib("newsgroups")) == NULL) {
- X puts("Couldn't open LIB/newsgroups file");
- X exit(2);
- X }
- X
- X gp = (dir_list *)&groups;
- X while (fgets(buf, (int)sizeof buf, fp) != NULL) {
- X len = strlen(buf) - 1;
- X buf[len] = '\0';
- X if ((gp->next = (dir_list *)malloc(4 + len + 1)) == NULL) {
- X puts("Malloc failed!");
- X exit(4);
- X }
- X gp = gp->next;
- X strcpy(gp->name, buf);
- X }
- X gp->next = NULL;
- X
- X fclose(fp);
- X}
- X
- Xstatic char *
- Xng(register int i)
- X{
- X register dir_list *gp;
- X register int II = i;
- X static char *NAME;
- X static int I = -1;
- X
- X if (i == I)
- X return NAME;
- X
- X for (gp = (dir_list *)&groups; (gp = gp->next) != NULL; ) {
- X if (--i < 0) {
- X I = II;
- X return (NAME = gp->name);
- X }
- X }
- X return NULL;
- X}
- X
- Xstatic char *GroupHelp[] = {
- X "y/Y Read this newsgroup (default)",
- X "n/N Skip this newsgroup",
- X "- Go back to previous news group",
- X "^ Go back to first news group",
- X "= List article subjects in this newsgroup",
- X "p Post to this news group",
- X "h/H/? Display help",
- X "q/Q Quit to DOS\n",
- X 0
- X};
- X
- Xint
- Xmain(ac, av)
- Xchar **av;
- X{
- X int ch, cnt, nbr;
- X char *curgp;
- X int found1 = 0;
- X int current = -1;
- X int old, last = 0;
- X short i;
- X short notdone = 1;
- X
- X for (i = 1; i < ac; ++i) {
- X char *ptr = av[i];
- X
- X if (*ptr == '-') {
- X ptr += 2;
- X switch(ptr[-1]) {
- X case 'p':
- X if (*ptr)
- X reply(0, NULL, ptr);
- X else
- X reply(0, NULL, av[++i]);
- X notdone = 0;
- X break;
- X case 'r':
- X if (*ptr)
- X NumRows = atoi(ptr);
- X else
- X NumRows = atoi(av[++i]);
- X break;
- X case 'c':
- X if (*ptr)
- X NumCols = atoi(ptr);
- X else
- X NumCols = atoi(av[++i]);
- X break;
- X }
- X }
- X }
- X
- X if (notdone == 0) {
- X cooked(stdin);
- X exit(1);
- X }
- X
- X init();
- X
- X for (;;) {
- X NewGroup:
- X if ((curgp = ng(++current)) == NULL) {
- X if (!found1) {
- X puts("No News, use 'anews -p group' to post new articles");
- X do_quit();
- X } else {
- X found1 = 0, current = -1;
- X continue;
- X }
- X }
- X
- X while ((nbr = scan_directory(curgp)) != 0) {
- X old = last, last = current;
- X RepeatGroup:
- X Cr, Clear_eol;
- X ON;
- X cnt = unread_count();
- X printf("%d articles in %s (%d unread)? [%s]",
- X nbr, curgp, cnt, (cnt == 0) ? "n/y" : "y/n"
- X );
- X OFF;
- X putchar(' ');
- X ch = rawch();
- X if (ch == ' ')
- X ch = (cnt == 0) ? 'n' : 'y';
- X
- X switch (ch) {
- X case 'y':
- X case 'Y':
- X ++found1;
- X if (cnt == 0)
- X rewind_arts();
- X ch = readgroup(curgp);
- X if (ch == 'q')
- X do_quit();
- X if (ch == '$')
- X goto NewGroup;
- X if (ch)
- X break;
- X /* Fall through to... */
- X case 'q':
- X case 'Q':
- X putchar('\n');
- X do_quit();
- X case 'n':
- X case 'N':
- X putchar('\n');
- X goto NewGroup;
- X case '^':
- X current = -1;
- X goto NewGroup;
- X case '-':
- X current = old - 1;
- X goto NewGroup;
- X/* FIXME add case to go directly to a specific (named) news group */
- X case 'h':
- X case 'H':
- X case '?':
- X do_help(GroupHelp);
- X goto RepeatGroup;
- X case '=':
- X putchar('\n');
- X scan_subjects(curgp);
- X goto RepeatGroup;
- X case 'p':
- X putchar('\n');
- X reply(0, NULL, curgp);
- X goto RepeatGroup;
- X }
- X }
- X }
- X return 0;
- X}
- X
- Xchar *
- XGet_Env(char *envar, char *def)
- X{
- X char *p, *eptr;
- X
- X if ((p = getenv(envar)) != NULL) {
- X eptr = (char *)malloc(strlen(p) + 1);
- X strcpy(eptr, p);
- X } else {
- X eptr = def;
- X }
- X return(eptr);
- X}
- X
- Xvoid
- Xinit()
- X{
- X NewsDir = GetConfigDir(UUNEWS);
- X if (access(NewsDir, 0) == -1) {
- X printf("FATAL - couldn't access %s\n", NewsDir);
- X exit(1);
- X }
- X fg = *Get_Env("FG", "8");
- X bg = *Get_Env("BG", "0");
- X initgroups();
- X}
- X
- Xstatic char buf[BUFSIZ];
- X
- Xchar *
- Xsubs(char *newsfile)
- X{
- X FILE *fp;
- X int j;
- X
- X if ((fp = fopen(newsfile, "r")) == NULL) {
- X printf("Couldn't open %s\n", newsfile);
- X return(NULL);
- X }
- X j = 0;
- X while ( (j++<50) && (fgets(buf, (int)sizeof buf, fp) != NULL)) {
- X if (strncmp("Subject:", buf, 8) == 0) {
- X buf[strlen(buf)-1] = '\0';
- X fclose(fp);
- X return (buf + 8);
- X }
- X }
- X fclose(fp);
- X return NULL;
- X}
- X
- Xvoid
- Xdo_quit(void)
- X{
- X exit(0);
- X}
- X
- Xvoid
- Xdo_help(char **pp)
- X{
- X printf("\x9bH\x9bJ\033[0;1;33;40m\r");
- X do {
- X puts(*pp);
- X } while (*++pp != NULL);
- X printf("\033[0;31;40m");
- X}
- X
- Xchar *
- Xart2file(char *group, char *art)
- X{
- X static char path[128];
- X
- X sprintf(path, "%s/%s", expand_path(NewsDir, group), art);
- X return path;
- X}
- X
- Xint
- Xreadgroup(char *group)
- X{
- X register int ch;
- X register char *name;
- X char newname[128];
- X
- X while (name = first_unread()) {
- X named_art:
- X switch (ch = showart(group, name)) {
- X case 'd':
- X case 'D':
- X del_cur_art(1);
- X /* fall through to... */
- X
- X case 'n':
- X case 'N':
- X mark_cur_art(1);
- X break;
- X
- X case 'q':
- X free_directory(1);
- X return('x');
- X case 'Q':
- X free_directory(0);
- X return ('x');
- X
- X case '$':
- X free_directory(1);
- X return '$';
- X
- X case '-':
- X name = get_prev_art();
- X goto named_art;
- X
- X case '^':
- X rewind_arts();
- X break;
- X
- X case '0':
- X case '1':
- X case '2':
- X case '3':
- X case '4':
- X case '5':
- X case '6':
- X case '7':
- X case '8':
- X case '9':
- X newname[0] = ch;
- X ON;
- X printf("Goto Article");
- X OFF;
- X printf(" #%c", ch);
- X fflush(stdout);
- X gets(newname+1);
- X
- X if ((name = goto_article(newname)) == NULL) {
- X /* FIXME -- handle illegal article */
- X break; /* DEBUG */
- X }
- X goto named_art;
- X
- X case '.':
- X case '>':
- X case ',':
- X case '<':
- X for(;;) {
- X printf("\r #%s\t%-50s", name, subs(art2file(group, name)));
- X ON;
- X printf("\rGoto Article");
- X OFF;
- X switch (rawch()) {
- X case '>':
- X case '.':
- X if ((name = get_next_art()) == NULL) {
- X /* wrap around to begining */
- X name = get_next_art();
- X }
- X break;
- X case ',':
- X case '<':
- X name = get_prev_art();
- X break;
- X default:
- X goto named_art;
- X }
- X }
- X default:
- X break;
- X }
- X }
- X free_directory(1);
- X return ('n');
- X}
- X
- Xvoid
- Xscr_inverse_on(void)
- X{
- X printf("\x9b\x37;3%c;4%cm", fg, bg);
- X}
- X
- Xvoid
- Xscr_inverse_off(void)
- X{
- X printf("\x9b\x30;33;40m\033[0m");
- X}
- X
- Xrawch(void)
- X{
- X register int ch;
- X
- X fflush(stdout);
- X raw(stdin);
- X ch = getchar();
- X cooked(stdin);
- X return (ch);
- X}
- X
- END_OF_FILE
- if test 6709 -ne `wc -c <'uucp2/src/anews/news.c'`; then
- echo shar: \"'uucp2/src/anews/news.c'\" unpacked with wrong size!
- fi
- # end of 'uucp2/src/anews/news.c'
- fi
- if test -f 'uucp2/src/anews/unpackmail.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'uucp2/src/anews/unpackmail.c'\"
- else
- echo shar: Extracting \"'uucp2/src/anews/unpackmail.c'\" \(5525 characters\)
- sed "s/^X//" >'uucp2/src/anews/unpackmail.c' <<'END_OF_FILE'
- X
- X/*
- X * UNPACKMAIL.C
- X */
- X
- X#include "news.h"
- X#include <expand_path.h>
- X#include <ctype.h>
- X
- Xstatic FILE *mp;
- X
- Xstatic void
- XCloseOldFile(void)
- X{
- X if (mp) {
- X fflush(mp);
- X if (fclose(mp) != 0) {
- X printf("FATAL -- I/O error while writing message\n");
- X exit(20);
- X }
- X mp = NULL;
- X }
- X}
- X
- Xstatic int
- XNewFile(char *dir, int count)
- X{
- X char namebuf[64];
- X
- X CloseOldFile();
- X
- X do {
- X sprintf(namebuf, "%s/%d", dir, ++count);
- X } while (access(namebuf, 0) == 0);
- X
- X if ((mp = fopen(namebuf, "w")) == NULL) {
- X printf("FATAL -- can't create %s to hold new message\n", namebuf);
- X exit(10);
- X }
- X printf("%4d: ", count);
- X return (count);
- X}
- X
- Xstatic void
- Xcopyline(register char *buf, FILE *fp)
- X{
- X register int c;
- X
- X if (mp == NULL)
- X return;
- X
- X while (*buf != '\0') {
- X putc(*buf, mp);
- X if (*buf == '\n')
- X return;
- X ++buf;
- X }
- X while ((c = getc(fp)) != EOF) {
- X putc(c, mp);
- X if (c == '\n')
- X return;
- X }
- X}
- X
- Xstatic int
- Xreal_from(char *buffer, char *who)
- X{
- X /*
- X * returns true if 's' has the seven 'from' fields,
- X * initializing the who to the sender
- X * also returns true if has dmail ARCHIVE flag
- X */
- X char fld3[20], fld7[20];
- X
- X if (strncmp(buffer, "From ", 5) != 0)
- X return (0);
- X
- X fld7[0] = '\0';
- X sscanf(buffer, "%*s %s %s %*s %*s %*s %s", who, fld3, fld7);
- X if (fld7[0] != '\0')
- X return (1);
- X if (strcmp(fld3, "(ARCHIVE)") != 0)
- X return (0);
- X strcpy(who, fld3);
- X return (1);
- X}
- X
- Xstatic void
- Xforwarded(char *buffer, char *who)
- X{
- X /*
- X * change 'from' and date fields to reflect the ORIGINATOR of
- X * the message by iteratively parsing the >From fields...
- X */
- X char machine[80], buff[80];
- X
- X machine[0] = '\0';
- X sscanf(buffer, "%*s %s %*s %*s %*s %*s %*s %*s %*s %s", who, machine);
- X
- X if (machine[0] == '\0') /* try for srm address */
- X sscanf(buffer, "%*s %s %*s %*s %*s %*s %*s %*s %s", who, machine);
- X
- X if (machine[0] == '\0')
- X sprintf(buff, "anonymous");
- X else
- X sprintf(buff, "%s!%s", machine, who);
- X
- X strncpy(who, buff, 80);
- X}
- X
- Xstatic void
- Xremove_first_word(char *dest, char *string)
- X{
- X /*
- X * Removes first word of string, i.e., up to first non-white space
- X * following a white space, and copies it to the destination.
- X */
- X while (!isspace(*string))
- X ++string;
- X while (isspace(*string))
- X ++string;
- X while (*dest++ = *string++)
- X ;
- X if (dest[-2] == '\n')
- X dest[-2] = '\0';
- X}
- X
- Xstatic void
- Xshow_header(char *from, char *subject)
- X{
- X /*
- X * output header in clean format, including abbreviation
- X * of return address if more than one machine name is
- X * contained within it!
- X */
- X register char *p, *q, *r;
- X
- X#ifdef PREFER_UUCP
- X if (chloc(from, '!') != -1 && chloc(from, '@') > 0) {
- X for (p=from; *p != '@'; p++)
- X ;
- X *p = '\0';
- X }
- X#endif
- X
- X p = from;
- X q = from; /* find address portion */
- X while ((r = strchr(q, '!')) != NULL) {
- X p = q;
- X q = r + 1;
- X }
- X
- X printf("%-30s %s\n", p, subject);
- X}
- X
- Xstatic void
- Xparse_arpa_from(char *buffer, char *newfrom)
- X{
- X /*
- X * Try to parse the 'From:' line given... It can be in one of
- X * two formats:
- X * From: Dave Taylor <hpcnou!dat>
- X * or From: hpcnou!dat (Dave Taylor)
- X * Change 'newfrom' ONLY if sucessfully parsed this entry and
- X * the resulting name is non-null!
- X */
- X register char *p, *q;
- X register int i;
- X
- X if (*(q = buffer + strlen(buffer) - 1) == '>') {
- X p = buffer + 6, q = p; /* skip "From: " */
- X do {
- X ++q;
- X } while (*q != '\0' && *q != '<' && *q != '(');
- X } else if (*q == ')') {
- X p = q;
- X do {
- X --p;
- X } while ((p > buffer + 5) && *p != '(' && *p != '<');
- X } else
- X return;
- X
- X if (p >= q)
- X return;
- X
- X /* remove leading spaces... */
- X while (isspace(*++p))
- X ;
- X
- X /* remove trailing spaces... */
- X while (isspace(*--q))
- X ;
- X
- X /* if anything is left, let's change 'from' value! */
- X if (p >= q)
- X return;
- X i = p - q + 1;
- X strncpy(newfrom, p, i)[i] = '\0';
- X}
- X
- Xstatic char buffer[1000];
- Xstatic char from_whom[512], subject[512];
- X
- Xint
- Xunpackmail(char *dir, int count)
- X{
- X register FILE *fp;
- X register char *mailfile;
- X
- X if (access(mailfile = expand_path(dir, ".mailfile"), 0) != 0)
- X return count;
- X if ((fp = fopen(mailfile, "r")) == NULL)
- X return count;
- X mailfile = fgets(buffer, (int)sizeof buffer, fp);
- X fclose(fp);
- X if (mailfile == NULL)
- X return count;
- X if ((mailfile = strchr(buffer, '\n')) != NULL)
- X *mailfile = '\0';
- X if ((fp = fopen(buffer, "r")) == NULL)
- X return count;
- X mailfile = strdup(buffer);
- X
- X printf("New mail:\n");
- X mp = NULL;
- X while (fgets(buffer, (int)sizeof buffer, fp) != NULL) {
- X if (real_from(buffer, from_whom)) {
- X count = NewFile(dir, count);
- X } else if (from_whom[0] != '\0') {
- X if (strncmp(buffer, ">From ", 6) == 0) {
- X forwarded(buffer, from_whom);
- X } else if (strncmp(buffer, "Subject:", 8) == 0 || strncmp(buffer, "Re:", 3) == 0) {
- X if (subject[0] == '\0')
- X remove_first_word(subject, buffer);
- X } else if (strncmp(buffer, "From:", 5) == 0)
- X parse_arpa_from(buffer, from_whom);
- X else if (buffer[0] == '\n') {
- X show_header(from_whom, subject);
- X from_whom[0] = 0, subject[0] = 0;
- X }
- X }
- X copyline(buffer, fp);
- X }
- X fclose(fp);
- X CloseOldFile();
- X
- X#ifndef TEST
- X remove(mailfile);
- X#else
- X printf("remove(%s)\n", mailfile);
- X#endif
- X free(mailfile);
- X return count;
- X}
- X
- X#ifdef TEST
- Xmain(int argc, char **argv)
- X{
- X printf("New value of count is %d\n", unpackmail("UUNEWS:mail.test", 9));
- X return 0;
- X}
- X#endif
- X
- END_OF_FILE
- if test 5525 -ne `wc -c <'uucp2/src/anews/unpackmail.c'`; then
- echo shar: \"'uucp2/src/anews/unpackmail.c'\" unpacked with wrong size!
- fi
- # end of 'uucp2/src/anews/unpackmail.c'
- fi
- if test -f 'uucp2/src/dmail/main.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'uucp2/src/dmail/main.c'\"
- else
- echo shar: Extracting \"'uucp2/src/dmail/main.c'\" \(6263 characters\)
- sed "s/^X//" >'uucp2/src/dmail/main.c' <<'END_OF_FILE'
- X
- X/*
- X * MAIN.C
- X *
- X * $Header: Beta:src/uucp/src/dmail/RCS/main.c,v 1.1 90/02/02 12:03:43 dillon Exp Locker: dillon $
- X *
- X * (C) Copyright 1985-1990 by Matthew Dillon, All Rights Reserved.
- X *
- X * Global Routines: MAIN()
- X * INIT()
- X * SIG_HANDLE()
- X *
- X * Static Routines: none.
- X */
- X
- X#include <pwd.h>
- X#include <stdio.h>
- X#include <signal.h>
- X#include <sys/types.h>
- X#include <sys/stat.h>
- X#include <config.h>
- X#include "version.h"
- X
- X#include "dmail.h"
- X
- XIDENT(".04");
- Xchar *dillon_cpr = DCOPYRIGHT;
- X
- X#define MAILHOME MakeConfigPath(UUMAIL, "")
- X#define MBOX MakeConfigPath(UUMAIL, "mbox")
- X#define ALT_MBOX MakeConfigPath(UUMAIL, ".mbox")
- X#define MAILRC MakeConfigPath(UULIB, ".dmailrc")
- X#define VISUAL GetConfig(EDITOR, "dme")
- X
- Xvoid init();
- X
- Xmain(argc, argv)
- Xchar *argv[];
- X{
- X int i, next, Retry;
- X int fop = 0, oop = 0;
- X int rcload = 1;
- X int options = 1;
- X int no_mail_overide = 0;
- X int nc = 0;
- X static int nameslist[128];
- X char *rcname;
- X
- X if (push_base())
- X done (1);
- X
- X init();
- X rcname = malloc (strlen(home_dir) + strlen(MAILRC) + 2);
- X#ifdef AMIGA
- X rcname[0] = 0;
- X#else
- X strcpy (rcname, home_dir);
- X strcat (rcname, "/");
- X#endif
- X strcat (rcname, MAILRC);
- X for (i = 1; i < argc; ++i) {
- X next = 0;
- X if ((*argv[i] == '-') && options) {
- X if (*(argv[i] + 1) == '\0') {
- X options = 0;
- X continue;
- X }
- X while (*++argv[i]) {
- X switch (*argv[i]) {
- X case 'S':
- X lmessage_overide = 1;
- X break;
- X case 'O':
- X no_mail_overide = 1;
- X break;
- X case 'l':
- X rcload = 1;
- X if (i + 1 < argc && *argv[i + 1] != '-') {
- X xfree (rcname);
- X oop = 1;
- X ++i;
- X ++next;
- X rcname = malloc (strlen (argv[i]) + 1);
- X strcpy (rcname, argv[i]);
- X }
- X break;
- X case 'L':
- X rcload = 0;
- X break;
- X case 'D':
- X XDebug = 1;
- X break;
- X case 'F':
- X if (++i < argc) {
- X add_extra (argv[i]);
- X } else {
- X puts (" -F Requires Field argument");
- X exit (1);
- X }
- X ++next;
- X break;
- X case 'v':
- X set_var (LEVEL_SET, "verbose", "");
- X break;
- X case 'o':
- X xfree (output_file);
- X if (i + 1 < argc && *argv[i + 1] != '-') {
- X oop = 1;
- X ++i;
- X ++next;
- X output_file = malloc (strlen (argv[i]) + 1);
- X strcpy (output_file, argv[i]);
- X } else {
- X oop = -1;
- X output_file = malloc (strlen(home_dir) +
- X strlen(ALT_MBOX) + 2);
- X#ifdef AMIGA
- X strcpy (output_file, ALT_MBOX);
- X#else
- X sprintf (output_file, "%s/%s", home_dir, ALT_MBOX);
- X#endif
- X }
- X break;
- X case 'f':
- X if (i + 1 < argc && *argv[i + 1] != '-') {
- X fop = 1;
- X ++i;
- X ++next;
- X mail_file = realloc (mail_file, strlen (argv[i]) + 1);
- X strcpy (mail_file, argv[i]);
- X } else {
- X fop = -1;
- X mail_file = realloc (mail_file,
- X strlen(home_dir) + strlen(MBOX) + 2);
- X#ifdef AMIGA
- X strcpy (mail_file, MBOX);
- X#else
- X sprintf (mail_file, "%s/%s", home_dir, MBOX);
- X#endif
- X }
- X break;
- X default:
- X puts ("dmail: Bad argument");
- X puts ("dmail -O then 'help' for help.");
- X done (1);
- X }
- X if (next)
- X break;
- X }
- X } else {
- X No_load_mail = 1;
- X nameslist[nc++] = i;
- X }
- X }
- X if (oop == -1 && fop == -1) {
- X mail_file = realloc (mail_file, strlen(output_file) + 1);
- X strcpy (mail_file, output_file);
- X }
- Xends:
- X initial_load_mail();
- X m_select (Nulav, M_RESET);
- X Current = indexof (1);
- X if (nc)
- X set_var (LEVEL_SET, "comlinemail", "");
- X if (rcload) {
- X ac = 2;
- X av[1] = rcname;
- X do_source(rcname, 1);
- X }
- X if (nc) {
- X av[0] = "mail";
- X for (i = 0; i < nc; ++i)
- X av[i + 1] = argv[nameslist[i]];
- X ac = nc + 1;
- X do_reply ("", R_MAIL);
- X done (0);
- X }
- X if (Entries + no_mail_overide == 0) {
- X printf ("\nNO MAIL for %s\n\n", user_name);
- X return;
- X }
- X printf ("\nRF %-20s WF %-20s\n", mail_file, output_file);
- X do {
- X Retry = 20;
- X pop_base();
- Xloop:
- X if (push_base()) {
- X pop_base();
- X if (XDebug)
- X printf ("TOP LEVEL INTR, Level: %d\n", Longstack);
- X if (--Retry == 0)
- X done (1);
- X puts ("");
- X goto loop;
- X }
- X check_new_mail();
- X } while (do_command() > 0);
- X
- X return(0);
- X}
- X
- Xvoid
- Xinit()
- X{
- X char *str;
- X struct passwd *passwd;
- X extern int sig_handle();
- X
- X Entry = (struct ENTRY *)malloc (sizeof(*Entry));
- X Entry->status = Entry->no = Entry->fpos = 0;
- X passwd = getpwuid(getuid());
- X if (passwd == NULL) {
- X printf("DMail, unable to get passwd entry for uid %d\n", getuid());
- X exit(1);
- X }
- X user_name = malloc (strlen(passwd->pw_name) + 1);
- X home_dir = malloc (strlen(passwd->pw_dir) + 1);
- X visual = malloc (strlen(VISUAL) + 1);
- X strcpy (visual , VISUAL);
- X strcpy (user_name, passwd->pw_name);
- X strcpy (home_dir , passwd->pw_dir);
- X#ifdef AMIGA
- X if (str = FindConfig(HOME))
- X strcpy ((home_dir = realloc (home_dir, strlen(str) + 1)), str);
- X if (str = FindConfig(USERNAME))
- X strcpy ((user_name = realloc (user_name, strlen(str) + 1)), str);
- X if (str = FindConfig(EDITOR))
- X strcpy ((visual = realloc (visual, strlen(str) + 1)), str);
- X
- X if (str = MallocEnviro("USER"))
- X user_name = str;
- X
- X#else
- X if ((str = getenv ("HOME")) != NULL)
- X strcpy ((home_dir = realloc (home_dir, strlen(str) + 1)), str);
- X if ((str = getenv ("USER")) != NULL)
- X strcpy ((user_name = realloc (user_name, strlen(str) + 1)), str);
- X if ((str = getenv ("VISUAL")) != NULL)
- X strcpy ((visual = realloc (visual, strlen(str) + 1)), str);
- X#endif
- X mail_file = malloc (strlen(MAILHOME) + strlen(user_name) + 1);
- X sprintf (mail_file , "%s%s", MAILHOME, user_name);
- X output_file = malloc (strlen(home_dir) + 2 + strlen(MBOX) + 1);
- X#ifdef AMIGA
- X strcpy(output_file, MBOX);
- X#else
- X sprintf (output_file, "%s/%s", home_dir, MBOX);
- X#endif
- X fix_globals();
- X#ifdef UNIX
- X signal (SIGHUP, sig_handle);
- X signal (SIGINT, sig_handle);
- X signal (SIGPIPE, SIG_IGN);
- X#endif
- X#ifdef AMIGA
- X signal (SIGINT, sig_handle);
- X#endif
- X}
- X
- Xsig_handle()
- X{
- X#ifdef UNIX
- X int mask = sigblock (0);
- X
- X sigsetmask (mask & ~((1 << SIGHUP) | (1 << SIGINT)));
- X#endif
- X#ifdef AMIGA
- X signal (SIGINT, sig_handle); /* reload signal */
- X#endif
- X if (Longstack && !Breakstack)
- X longjmp (env[Longstack], 1);
- X return(0);
- X}
- X
- Xget_inode(file)
- Xchar *file;
- X{
- X struct stat stats;
- X
- X if (stat (file, &stats) < 0)
- X return (-1);
- X return (stats.st_ino);
- X}
- X
- END_OF_FILE
- if test 6263 -ne `wc -c <'uucp2/src/dmail/main.c'`; then
- echo shar: \"'uucp2/src/dmail/main.c'\" unpacked with wrong size!
- fi
- # end of 'uucp2/src/dmail/main.c'
- fi
- if test -f 'uucp2/src/dmail/sub.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'uucp2/src/dmail/sub.c'\"
- else
- echo shar: Extracting \"'uucp2/src/dmail/sub.c'\" \(5006 characters\)
- sed "s/^X//" >'uucp2/src/dmail/sub.c' <<'END_OF_FILE'
- X
- X/*
- X * SUB.C
- X *
- X * $Header: Beta:src/uucp/src/dmail/RCS/sub.c,v 1.1 90/02/02 12:03:38 dillon Exp Locker: dillon $
- X *
- X * (C) Copyright 1985-1990 by Matthew Dillon, All Rights Reserved.
- X *
- X * Global Routines: INDEXOF()
- X * SIG()
- X * POSITION_CURRENT()
- X * SKIP_TO_DATE()
- X * GET_FIELD()
- X * COMPILE_FIELD()
- X * ISFROM()
- X * XSTRNCMP()
- X * NEXT_WORD()
- X * DONE()
- X *
- X */
- X
- X#include <signal.h>
- X#include <stdio.h>
- X#include "dmail.h"
- X#include "config.h"
- X
- X#ifdef UNIX
- Xextern FILE *popen();
- X#endif
- X
- Xxfree(ptr)
- Xchar *ptr;
- X{
- X static char *sptr;
- X
- X if (sptr)
- X free (sptr);
- X sptr = ptr;
- X return (1);
- X}
- X
- X
- Xindexof(num)
- Xregister int num;
- X{
- X register int i, last;
- X
- X if (num < 1)
- X num = -1;
- X for (last = -1, i = 0; i < Entries; ++i) {
- X if (Entry[i].no) {
- X last = i;
- X if (Entry[i].no == num)
- X return (i);
- X }
- X }
- X if (num == -1 && last >= 0)
- X return (last);
- X return (-1);
- X}
- X
- Xvoid
- Xnull()
- X{
- X}
- X
- X
- Xposition_current()
- X{
- X int pos;
- X
- X if (!m_fi)
- X return(0);
- X if (Current >= 0) {
- X pos = Entry[Current].fpos;
- X if (fseek (m_fi, pos, 0) < 0 || ftell(m_fi) != pos)
- X puts ("ERROR: Cannot position file to message");
- X } else {
- X fseek (m_fi, 0, 0);
- X }
- X}
- X
- X
- Xskip_to_data(fi)
- XFILE *fi;
- X{
- X static char buf[MAXFIELDSIZE];
- X
- X while (fgets (buf, MAXFIELDSIZE, fi) != NULL) {
- X if (*buf == '\n')
- X return (1);
- X }
- X return (-1);
- X}
- X
- X
- Xchar *
- Xget_field(str)
- Xchar *str;
- X{
- X int i, entry = Current;
- X int len = strlen(str);
- X
- X if (Current < 0)
- X return("");
- X i = get_extra (str);
- X if (i >= 0)
- X return (Entry[entry].fields[i]);
- X if (m_fi == NULL)
- X return ("");
- X fseek (m_fi, Entry[entry].fpos, 0);
- X while (fgets (Buf, MAXFIELDSIZE, m_fi) != NULL) {
- X if (isfrom (Buf))
- X break;
- X if (strncmp (Buf, str, len) == 0) {
- X Buf[strlen(Buf) - 1] = '\0';
- X compile_field(Buf, m_fi);
- X return (next_word (Buf));
- X }
- X }
- X return ("");
- X}
- X
- X
- Xcompile_field(buf, fi)
- Xchar *buf;
- XFILE *fi;
- X{
- X int len, acc, pos;
- X
- X acc = 0;
- X buf += strlen (buf) + 1;
- X pos = ftell (fi);
- X while (fgets (buf, MAXFIELDSIZE - acc, fi) != NULL) {
- X if (*buf == ' ' || *buf == 9) {
- X *(buf - 1) = '\n';
- X len = strlen (buf) - 1;
- X *(buf + len) = '\0';
- X buf += len;
- X acc += len + 2;
- X if (acc > MAXFIELDSIZE - 10) {
- X printf ("Warning: Field size beyond %d bytes\n", MAXFIELDSIZE);
- X sleep (2);
- X return (1);
- X }
- X } else {
- X *buf = '\0';
- X fseek (fi, pos, 0);
- X return (1);
- X }
- X pos = ftell (fi);
- X }
- X fseek (fi, pos, 0);
- X}
- X
- X
- Xisfrom(str)
- Xregister char *str;
- X{
- X static char from[] = {"From "};
- X register int i = 0;
- X
- X while (i < 5) {
- X if (*str++ != from[i++])
- X return (0);
- X }
- X return (1);
- X}
- X
- X
- Xxstrncmp (src, dest, len)
- Xregister char *src, *dest;
- Xregister int len;
- X{
- X while (--len >= 0) {
- X if ((*src & 0x1f) != (*dest & 0x1f)) {
- X if ((*src & 0x1f) < (*dest & 0x1f))
- X return (-1);
- X return (1);
- X }
- X ++src; ++dest;
- X }
- X return (0);
- X}
- X
- X
- X
- Xchar *
- Xnext_word(str)
- Xregister char *str;
- X{
- X while (*str && *str != ' ' && *str != 9)
- X ++str;
- X while (*str && (*str == ' ' || *str == 9))
- X ++str;
- X return (str);
- X}
- X
- Xvoid
- Xdone(n)
- X{
- X char scr[64];
- X
- X push_break();
- X sprintf (scr, "t:dmail%d", getpid());
- X unlink (scr);
- X sprintf (scr, "t:dmt%d", getpid());
- X unlink (scr);
- X unlink ("#");
- X exit (n);
- X}
- X
- Xvoid
- Xfix_globals()
- X{
- X char *ptr;
- X
- X push_break();
- X S_page = (ptr = get_var (LEVEL_SET, "page")) ?
- X ((*ptr) ? atoi (ptr) : 24) : -1;
- X if (S_page > 0 && (S_page -= 4) < 0)
- X S_page = 1;
- X
- X S_sendmail = (ptr = get_var (LEVEL_SET, "sendmail")) ? ptr : GetConfigProgram(SENDMAIL);
- X S_novibreak= (ptr = get_var (LEVEL_SET, "vibreak")) ? 0 : 1;
- X S_verbose = (ptr = get_var (LEVEL_SET, "verbose")) ? 1 : 0;
- X S_ask = (ptr = get_var (LEVEL_SET, "ask")) ? 1 : 0;
- X S_archive = (ptr = get_var (LEVEL_SET, "archive")) ? 1 : 0;
- X if (S_archive && *ptr == '\0')
- X S_archive = 0;
- X pop_break();
- X}
- X
- X
- X_pager(str, nl)
- Xchar *str;
- Xint nl;
- X{
- X static int count;
- X static FILE *fi;
- X static char buf[1024];
- X#ifdef UNIX
- X char *ptr;
- X#endif
- X
- X if (str == 0) {
- X switch (S_page) {
- X case -1:
- X count = 0;
- X return (1);
- X case 0:
- X#ifdef UNIX
- X ptr = get_var (LEVEL_SET, "page");
- X fi = popen (ptr, "w");
- X if (fi == NULL) {
- X count = 0;
- X printf ("CANNOT RUN PAGER PROGRAM: %s\n", ptr);
- X } else {
- X count = -1;
- X }
- X#else
- X count = 0;
- X fi = stdout;
- X#endif
- X return (1);
- X default:
- X count = 0;
- X return (1);
- X }
- X }
- X if ((long)str == -1) {
- X#ifdef UNIX
- X if (fi != NULL) {
- X pclose (fi);
- X fi = NULL;
- X }
- X#else
- X fi = NULL;
- X#endif
- X return (1);
- X }
- X if (count < 0) {
- X fputs (str, fi);
- X while (nl--)
- X fputs ("\n", fi);
- X } else {
- X fputs (str, stdout);
- X while (nl--) {
- X fputs ("\n", stdout);
- X ++count;
- X }
- X#ifdef AMIGA
- X fflush(stdout);
- X#endif
- X while (*str) {
- X if (*str++ == '\n')
- X ++count;
- X }
- X if (S_page > 0 && S_page <= count) {
- X count = 0;
- X puts ("\n-- more --");
- X gets(buf);
- X }
- X }
- X}
- X
- END_OF_FILE
- if test 5006 -ne `wc -c <'uucp2/src/dmail/sub.c'`; then
- echo shar: \"'uucp2/src/dmail/sub.c'\" unpacked with wrong size!
- fi
- # end of 'uucp2/src/dmail/sub.c'
- fi
- if test -f 'uucp2/src/lib/alias.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'uucp2/src/lib/alias.c'\"
- else
- echo shar: Extracting \"'uucp2/src/lib/alias.c'\" \(5044 characters\)
- sed "s/^X//" >'uucp2/src/lib/alias.c' <<'END_OF_FILE'
- X
- X/*
- X * ALIAS.C
- X *
- X * $Header: Beta:src/uucp/src/lib/RCS/alias.c,v 1.1 90/02/02 12:08:24 dillon Exp Locker: dillon $
- X *
- X * (C) Copyright 1989-1990 by Matthew Dillon, All Rights Reserved.
- X *
- X * Interpret UULIB:Aliases file. To save space we do not load
- X * the entire file, just sections on demand.
- X *
- X * # = comment
- X * id: name [, name...]
- X *
- X * name is a user name, path, or |filter, or quoted name. Example,
- X * "|more" or "|rnews"
- X */
- X
- X#include <stdio.h>
- X#include <stdlib.h>
- X#include <fcntl.h>
- X#include <time.h>
- X#include "config.h"
- X
- X#include "log.h"
- X
- X#define HASHSIZE 256
- X#define HASHMASK (HASHSIZE-1)
- X
- X#define HF_TERM 0x01 /* terminator name */
- X#define HF_ALIAS 0x02 /* alias */
- X#define HF_LOADED 0x04 /* def loaded */
- X
- Xtypedef struct Hash {
- X struct Hash *Next;
- X short NumAlias; /* # of aliases */
- X short Flags;
- X char *Name; /* aliased user name */
- X union {
- X struct Hash **Alias; /* list of aliases */
- X long Offset; /* offset into file */
- X } u;
- X} Hash;
- X
- XPrototype void LoadAliases(void);
- XPrototype void UserAliasList(const char *, void (*)(const char *));
- X
- XLocal Hash *FindHashObject(const char *);
- XLocal void LoadHashObject(Hash *);
- XLocal int HashFunc(const char *);
- X
- X
- Xstatic Hash *HashTab[HASHSIZE];
- Xstatic char Tmp[256];
- X
- Xvoid
- XLoadAliases()
- X{
- X FILE *fi = fopen(MakeConfigPath(UULIB, "Aliases"), "r");
- X short i;
- X short j;
- X short k;
- X short line = 0;
- X long newoffset = 0;
- X long offset;
- X Hash *h;
- X char *buf = Tmp;
- X
- X if (fi == NULL) {
- X ulog(-1, "Can't open %s", MakeConfigPath(UULIB, "Aliases"));
- X return;
- X }
- X while (fgets(buf, 256, fi)) {
- X offset = newoffset;
- X newoffset = ftell(fi);
- X ++line;
- X for (i = 0; buf[i] == ' ' || buf[i] == 9; ++i);
- X if (buf[i] == '#' || buf[i] == '\n')
- X continue;
- X for (j = i; buf[j] && buf[j] != ':'; ++j);
- X if (buf[j] == 0) {
- X ulog(-1, "No Colon %s line %d", MakeConfigPath(UULIB, "Aliases"), line);
- X continue;
- X }
- X buf[j] = 0;
- X
- X k = HashFunc(buf + i);
- X h = malloc(sizeof(Hash));
- X h->Next = HashTab[k];
- X h->NumAlias = 0;
- X h->Flags = HF_ALIAS;
- X h->Name = malloc(strlen(buf+i) + 1);
- X h->u.Offset = offset + j + 1;
- X strcpy(h->Name, buf + i);
- X
- X HashTab[k] = h;
- X
- X /*
- X * if trailing comma, list continues onto next line
- X */
- X
- X for (;;) {
- X for (++j; buf[j]; ++j);
- X while (buf[j-1] == ' ' || buf[j-1] == 9 || buf[j-1] == '\n')
- X --j;
- X if (buf[j-1] != ',')
- X break;
- X if (fgets(buf, 256, fi) == NULL)
- X break;
- X newoffset = ftell(fi);
- X j = 0;
- X }
- X }
- X fclose(fi);
- X}
- X
- Xstatic
- XHash *
- XFindHashObject(name)
- Xconst char *name;
- X{
- X short k = HashFunc(name);
- X Hash *h;
- X
- X for (h = HashTab[k]; h; h = h->Next) {
- X if (strcmp(name, h->Name) == 0)
- X return(h);
- X }
- X return(NULL);
- X}
- X
- Xstatic
- Xvoid
- XLoadHashObject(hash)
- XHash *hash;
- X{
- X FILE *fi = fopen(MakeConfigPath(UULIB, "Aliases"), "r");
- X char *buf = Tmp;
- X short i, j;
- X short c;
- X short numalloc = 4;
- X Hash **hv = malloc(sizeof(Hash *) * 4);
- X Hash *h;
- X
- X if (fi == NULL) {
- X ulog(-1, "Can't open %s", MakeConfigPath(UULIB, "Aliases"));
- X return;
- X }
- X
- X hash->Flags |= HF_LOADED;
- X fseek(fi, hash->u.Offset, 0);
- X while (fgets(buf, 256, fi)) {
- X i = 0;
- X c = 'x';
- X
- X for (;;) {
- X while (buf[i] == ' ' || buf[i] == 9)
- X ++i;
- X if (buf[i] == 0 || buf[i] == '\n')
- X break;
- X
- X for (j = i; buf[j] != '\n' && buf[j] != ' ' && buf[j] != 9 && buf[j] != ','; ++j) {
- X if (buf[j] == '\"') {
- X i = j + 1;
- X for (++j; buf[j] != '\n' && buf[j] != '\"'; ++j);
- X break;
- X }
- X }
- X c = buf[j];
- X buf[j] = 0;
- X
- X if ((h = FindHashObject(buf + i)) == NULL) {
- X short k = HashFunc(buf + i);
- X
- X h = malloc(sizeof(Hash));
- X h->Next = HashTab[k];
- X h->NumAlias = 0;
- X h->Flags = HF_TERM;
- X h->Name = malloc(strlen(buf + i) + 1);
- X h->u.Alias = NULL;
- X strcpy(h->Name, buf + i);
- X
- X HashTab[k] = h;
- X }
- X
- X if (hash->NumAlias == numalloc) {
- X Hash **hvo = hv;
- X short add = 4;
- X
- X hv = malloc(sizeof(Hash *) * (numalloc + add));
- X movmem((char *)hvo, (char *)hv, sizeof(Hash *) * numalloc);
- X numalloc += add;
- X }
- X hv[hash->NumAlias++] = h;
- X
- X i = j + 1;
- X if (c == '\"')
- X c = buf[i++];
- X if (c == '\n' || c == 0)
- X i = j;
- X }
- X if (c != ',')
- X break;
- X }
- X hash->u.Alias = hv;
- X}
- X
- Xvoid
- XUserAliasList(user, callback)
- Xconst char *user;
- Xvoid (*callback)(const char *);
- X{
- X short i;
- X Hash *hash = FindHashObject(user);
- X static short stack;
- X
- X if (++stack == 32) {
- X ulog(-1, "%s recursion near user %s", MakeConfigPath(UULIB, "Aliases"), user);
- X --stack;
- X return;
- X }
- X
- X if (hash && (hash->Flags & HF_TERM) == 0) {
- X if ((hash->Flags & HF_LOADED) == 0)
- X LoadHashObject(hash);
- X for (i = 0; i < hash->NumAlias; ++i) {
- X Hash *h = hash->u.Alias[i];
- X UserAliasList(h->Name, callback);
- X }
- X } else {
- X (*callback)(user);
- X }
- X --stack;
- X}
- X
- Xstatic int
- XHashFunc(str)
- Xconst char *str;
- X{
- X unsigned long v = 0x14FBA5C3;
- X while (*str) {
- X v = (v << 5) ^ (*str & 0x1F) ^ (v >> 27);
- X ++str;
- X }
- X return((int)(v & HASHMASK));
- X}
- X
- END_OF_FILE
- if test 5044 -ne `wc -c <'uucp2/src/lib/alias.c'`; then
- echo shar: \"'uucp2/src/lib/alias.c'\" unpacked with wrong size!
- fi
- # end of 'uucp2/src/lib/alias.c'
- fi
- if test -f 'uucp2/src/news/postnews.c.OLD' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'uucp2/src/news/postnews.c.OLD'\"
- else
- echo shar: Extracting \"'uucp2/src/news/postnews.c.OLD'\" \(4283 characters\)
- sed "s/^X//" >'uucp2/src/news/postnews.c.OLD' <<'END_OF_FILE'
- X
- X/*
- X * PostNews.c
- X *
- X * Copyright 1988 by William Loftus. All rights reserved.
- X *
- X * Version 0.60 Beta
- X *
- X * $Header: Beta:src/uucp/src/News060/postnews.c,v 1.1 90/02/02 11:44:07 dillon Exp Locker: dillon $
- X */
- X
- X#include <time.h>
- X#include <stdio.h>
- X#include <stdlib.h>
- X#include "log.h"
- X#include "version.h"
- X
- XIDENT(".02");
- X
- Xchar *UserName;
- Xchar *NodeName;
- Xchar *RealName;
- Xchar *NewsEditor;
- Xchar *DomainName;
- Xchar to_buf[128];
- Xchar grp_buf[128];
- Xchar dist_buf[128];
- Xchar subject_buf[128];
- Xchar *temp_file_name;
- X
- Xint seq;
- X
- Xchar *NewsFeed;
- X
- Xchar cmd[128];
- Xchar path[128];
- Xchar signature[121];
- X
- Xvoid read_ctl();
- Xvoid GetTo();
- Xvoid GetDist();
- Xvoid GetSubject();
- Xvoid GetMessage();
- Xvoid BuildRnews();
- Xvoid Signature();
- Xvoid PromptGet();
- Xchar *TmpFileName();
- Xchar *FindConfig();
- X
- Xvoid
- Xerrormsg (msg, ...)
- Xchar *msg;
- X{
- X printf(msg);
- X}
- X
- X
- Xvoid
- Xmain()
- X{
- X temp_file_name = TmpFileName(MakeConfigPath(UUSPOOL, "news"));
- X
- X LogProgram = "PostNews";
- X
- X UserName = FindConfig("UserName");
- X NodeName = FindConfig("NodeName");
- X NewsFeed = FindConfig("NewsFeed");
- X NewsEditor=FindConfig("NewsEditor");
- X RealName = FindConfig("RealName");
- X DomainName=FindConfig("DomainName");
- X
- X if (UserName == NULL || NodeName == NULL || NewsFeed == NULL ||
- X NewsEditor==NULL || RealName == NULL || DomainName == NULL)
- X {
- X printf("UULIB:Config incomplete, missing one or more of:\n");
- X printf(" UserName, NodeName, DomainName, NewsFeed, NewsEditor, RealName\n");
- X exit(1);
- X }
- X
- X GetTo();
- X GetDist();
- X GetSubject();
- X GetMessage();
- X BuildRnews();
- X}
- X
- Xvoid
- XGetTo()
- X{
- X PromptGet("Newsgroup(s): ", 0, grp_buf, sizeof(grp_buf), stdin);
- X}
- X
- Xvoid
- XGetDist()
- X{
- X FILE *fd;
- X char buf[128];
- X
- X if (!(fd = fopen(MakeConfigPath(UULIB, "news.distribution"), "r"))) {
- X errormsg("Can't Find news.distribution file");
- X exit(3);
- X }
- X
- X while (fgets(buf, sizeof buf, fd)) {
- X printf("%s", buf);
- X }
- X
- X PromptGet("Distribution: ", 0, dist_buf, sizeof(dist_buf), stdin);
- X}
- X
- Xvoid
- XGetSubject()
- X{
- X PromptGet("Subject: ", 1, subject_buf, sizeof(subject_buf), stdin);
- X}
- X
- Xvoid
- XGetMessage()
- X{
- X FILE *fp;
- X time_t t;
- X
- X seq = GetSequence(4);
- X
- X fp = fopen(temp_file_name, "w");
- X
- X if (fp) {
- X time(&t);
- X fprintf(fp,"Relay-Version: X-AmigaNEWS version 0.60 BETA; site %s%s\n", NodeName, DomainName);
- X fprintf(fp,"Posting-Version: X-AmigaNEWS version 0.60 BETA; site %s%s\n", NodeName, DomainName);
- X fprintf(fp,"Path: %s!%s\n", NodeName, UserName);
- X fprintf(fp,"From: %s@%s%s (%s)\n", UserName, NodeName, DomainName, RealName);
- X fprintf(fp,"Newsgroups: %s", grp_buf);
- X fprintf(fp,"Subject: %s", subject_buf);
- X fprintf(fp,"Message-Id: <%05d.AA%05d@%s%s>\n", seq, seq, NodeName, DomainName);
- X fprintf(fp,"Date: %s", ctime(&t));
- X fprintf(fp,"Followup-To: %s", grp_buf);
- X fprintf(fp,"Expires: \n");
- X fprintf(fp,"Keywords: \n");
- X fprintf(fp,"Distribution: %s\n\n", dist_buf);
- X
- X fclose(fp);
- X } else {
- X errormsg("Can't open temp file %s\n", temp_file_name);
- X exit(1);
- X }
- X
- X sprintf(cmd,"%s %s", NewsEditor, temp_file_name);
- X system(cmd);
- X
- X printf("Append .signature file? [y/n] ");
- X fgets(signature, sizeof signature, stdin);
- X if ((signature[0] | 0x20) != 'n') {
- X Signature();
- X printf(".signature file appended.\n");
- X }
- X}
- X
- Xvoid
- XBuildRnews()
- X{
- X NewsFeed[7] = '\0';
- X
- X sprintf(cmd, "UUX %s \"%s!rnews\"", temp_file_name, NewsFeed);
- X system(cmd);
- X remove(temp_file_name);
- X}
- X
- X/*
- X * Read the control file and grab a few parameters.
- X */
- X
- Xvoid
- XSignature()
- X{
- X FILE *fp;
- X FILE *sf;
- X char buff[128];
- X
- X fp = fopen(temp_file_name, "a"); /* should already exist!! */
- X
- X if (!fp) {
- X errormsg("Can't open temp file--%s\n", temp_file_name);
- X exit(1);
- X }
- X
- X fprintf(fp, "\n--\n");
- X
- X sf = fopen(MakeConfigPath(UULIB, ".signature"), "r");
- X
- X if (sf) {
- X while (NULL != fgets(buff, sizeof buff, sf)) {
- X fprintf(fp, "%s", buff);
- X }
- X fclose(sf);
- X } else {
- X errormsg("Can't open .signature file\n");
- X }
- X fclose(fp);
- X}
- X
- Xvoid
- XPromptGet(prompt, loop, buf, bufsize, fin)
- Xchar *prompt;
- Xchar *buf;
- XFILE *fin;
- X{
- X short i;
- X
- X do {
- X printf("%s", prompt);
- X fflush(stdout);
- X if (fgets(buf, bufsize, fin) == NULL)
- X break;
- X for (i = 0; buf[i] == ' ' || buf[i] == 9; ++i);
- X if (buf[i] != '\n')
- X break;
- X } while (loop);
- X}
- X
- X
- END_OF_FILE
- if test 4283 -ne `wc -c <'uucp2/src/news/postnews.c.OLD'`; then
- echo shar: \"'uucp2/src/news/postnews.c.OLD'\" unpacked with wrong size!
- fi
- # end of 'uucp2/src/news/postnews.c.OLD'
- fi
- if test -f 'uucp2/src/sendmail/domain.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'uucp2/src/sendmail/domain.c'\"
- else
- echo shar: Extracting \"'uucp2/src/sendmail/domain.c'\" \(4627 characters\)
- sed "s/^X//" >'uucp2/src/sendmail/domain.c' <<'END_OF_FILE'
- X
- X/*
- X * DOMAIN.C
- X *
- X * $Header: Beta:src/uucp/src/sendmail/RCS/domain.c,v 1.1 90/02/02 12:14:59 dillon Exp Locker: dillon $
- X *
- X * (C) Copyright 1989-1990 by Matthew Dillon, All Rights Reserved.
- X *
- X * Given the first machine in a path scan the domain list and
- X * return the type, class, and address of the resource entry.
- X *
- X * AUTOMATIC HACKS: scans L.sys file and automatically deals
- X * with machine[.UUCP] domain, returning
- X * Type=MD Class=UU Addr=machine.UUCP
- X */
- X
- X#include "defs.h"
- X
- XPrototype DomainLookup(char *, int, char *, char *, char *);
- XPrototype CompareDomain(char **, short, char **, short);
- X
- Xextern char *DefaultNode;
- Xextern char *NodeName;
- X
- Xint
- XDomainLookup(name, len, tb, cb, ab)
- Xchar *name;
- Xint len;
- Xchar *tb;
- Xchar *cb;
- Xchar *ab;
- X{
- X char *dary[16];
- X char *tmp = malloc(len + 1);
- X char *tbase = tmp;
- X short b, i;
- X short di;
- X FILE *fi;
- X short level; /* best domain level found so far */
- X static char buf[256];
- X
- X for (b = i = di = 0; i < len && name[i] != '!'; ++i) {
- X if (name[i] == '.') {
- X if (di == sizeof(dary)/sizeof(dary[0]) - 1) {
- X ulog(-1, "DomainLookup, too many domains! %s", name);
- X break;
- X }
- X strncpy(tmp, name + b, i - b);
- X tmp[i - b] = 0;
- X dary[di] = tmp;
- X tmp += i - b + 1;
- X b = i + 1;
- X ++di;
- X }
- X }
- X strncpy(tmp, name + b, i - b);
- X tmp[i - b] = 0;
- X dary[di++] = tmp;
- X
- X#ifdef NOTDEF
- X {
- X short i;
- X for (i = 0; i < di; ++i)
- X printf("XX '%s'\n", dary[i]);
- X }
- X#endif
- X
- X /*
- X * Check local mail
- X */
- X
- X level = 0;
- X
- X if (strcmpi(dary[0], NodeName) == 0) {
- X strcpy(tb, "--"); /* not used by caller */
- X strcpy(cb, "LL");
- X strcpy(ab, "--");
- X level = 1;
- X }
- X
- X if (level == 0 && (fi = fopen(MakeConfigPath(UULIB, "Domain"), "r"))) {
- X while (fgets(buf, sizeof(buf), fi)) {
- X short l2;
- X short di2 = 0;
- X char *dary2[16];
- X
- X if (buf[0] == ' ' || buf[0] == 9 || buf[0] == '\n' || buf[0] == '#')
- X continue;
- X for (b = i = 0; buf[i] && buf[i] != ' ' && buf[i] != 9; ++i) {
- X if (buf[i] == '.') {
- X if (di2 == sizeof(dary2)/sizeof(dary2[0]) - 1) {
- X ulog(-1, "%s, entry has too many subdomains: %s", MakeConfigPath(UULIB, "Domain"), buf);
- X break;
- X }
- X dary2[di2++] = buf + b;
- X buf[i] = 0;
- X b = i + 1;
- X }
- X }
- X buf[i] = 0;
- X dary2[di2++] = buf + b;
- X
- X buf[i] = 0; /* get domain name/wildcard */
- X
- X l2 = CompareDomain(dary, di, dary2, di2);
- X
- X#ifdef NOTDEF
- X {
- X short i;
- X printf("\nres %d\n", l2);
- X for (i = 0; i < di; ++i)
- X printf("#1 %s\n", dary[i]);
- X for (i = 0; i < di2; ++i)
- X printf("#2 %s\n", dary2[i]);
- X }
- X#endif
- X
- X if (l2 > level) { /* better domain then what we have */
- X sscanf(buf + i + 1, "%s %s %s", tb, cb, ab);
- X level = l2;
- X }
- X }
- X fclose(fi);
- X }
- X
- X /*
- X * Couldn't find the appropriate domain entry, check L.sys
- X * OR domain entry is a forwarder, check L.sys
- X */
- X
- X if (strcmp(tb, "MF") == 0 || level == 0) {
- X if (fi = fopen(MakeConfigPath(UULIB, "L.sys"), "r")) {
- X while (fgets(buf, sizeof(buf), fi)) {
- X if (buf[0] == ' ' || buf[0] == 9 || buf[0] == '#' || buf[0] == '\n')
- X continue;
- X for (i = 0; buf[i] && buf[i] != ' ' && buf[i] != 9; ++i);
- X buf[i] = 0;
- X if (strcmpi(dary[0], buf) == 0) {
- X strcpy(tb, "MD");
- X strcpy(cb, "UU");
- X strcpy(ab, buf);
- X strcat(ab, ".UUCP");
- X level = 1;
- X break;
- X }
- X }
- X fclose(fi);
- X }
- X }
- X
- X /*
- X * Couldn't find nothing, use DefaultNode
- X */
- X
- X if (level == 0) {
- X ulog(-1, "Warning, unable to interpret addr %s, using DefaultNode", name);
- X if (DefaultNode == NULL) {
- X ulog(-1, "Error, DefaultNode must exist if no Domain file");
- X printf("ERROR, no entry in Domain, L.sys, and\n");
- X printf("no DefaultNode config entry for %s\n", name);
- X puts("cannot send mail");
- X free(tbase);
- X return(0);
- X }
- X strcpy(tb, "MF");
- X strcpy(cb, "UU");
- X strcpy(ab, DefaultNode);
- X level = 1;
- X }
- X free(tbase);
- X return(level > 0);
- X}
- X
- X/*
- X * Compares a broken up address with a domain entry (buf).
- X */
- X
- Xint
- XCompareDomain(da1, di1, da2, di2)
- Xchar **da1;
- Xshort di1;
- Xchar **da2;
- Xshort di2;
- X{
- X short i, j;
- X short level = 0;
- X
- X for (i = di1 - 1, j = di2 - 1; i >= 0 && j >= 0; --i, --j) {
- X if (da2[j][0] == '*') {
- X ++level;
- X if (i && j == 0) /* so loop does not terminate */
- X ++j;
- X continue;
- X }
- X if (strcmpi(da1[i], da2[j]) == 0)
- X level += 2;
- X else {
- X if (j + 1 < di2 && da2[j+1][0] == '*') {
- X ++level;
- X ++j;
- X } else
- X return(0);
- X }
- X }
- X if (j >= 0) /* didn't exhaust domain entry */
- X return(0);
- X return((int)level);
- X}
- X
- END_OF_FILE
- if test 4627 -ne `wc -c <'uucp2/src/sendmail/domain.c'`; then
- echo shar: \"'uucp2/src/sendmail/domain.c'\" unpacked with wrong size!
- fi
- # end of 'uucp2/src/sendmail/domain.c'
- fi
- if test -f 'uucp2/src/unix/unshar.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'uucp2/src/unix/unshar.c'\"
- else
- echo shar: Extracting \"'uucp2/src/unix/unshar.c'\" \(6759 characters\)
- sed "s/^X//" >'uucp2/src/unix/unshar.c' <<'END_OF_FILE'
- X
- X/*
- X * UNSHAR.C
- X *
- X * $Header: Beta:src/uucp/src/compress/RCS/unshar.c,v 1.1 90/02/02 11:48:02 dillon Exp Locker: dillon $
- X *
- X * unshar -- undo a shell archive file
- X * (C) Copyright June 4 1987 by Craig Norborg
- X * Permission given to use this code in any form as long as it is
- X * not sold or marketed in any form without the written permission
- X * of its author. Removal of this copyright notice is expressly
- X * forbidden as well as any alteration of it.
- X */
- X/*
- X * Here is a small unshar program written to be as portable as possible.
- X * It was written under Aztec C on an Amiga and tested on a VAX 11/780,
- X * pdp11/70 and a Sequent Balance 21000. Any bug reports or enhancements
- X * should be reported to the author. Some further enhancements may
- X * include the correct handling of sub-directories and the handling of
- X * btoa/atob type shars. If you find a type of shar that this code
- X * does not work on, please send it to me, doc@j.cc.purdue.edu.
- X */
- X
- X#include <stdio.h>
- X#include <ctype.h>
- X#include <string.h>
- X#include "version.h"
- X
- XIDENT(".00");
- X
- X#ifdef unix
- X#include <sys/file.h>
- X#endif unix
- X#ifdef AMIGA
- X#define F_OK 0
- X#endif AMIGA
- X
- X#define BUFSIZE 512 /* Max length of an input line */
- X#define STRLEN 25 /* Max length of a file name or delimiter */
- X#define CAT "cat" /* The name of the 'cat' program */
- X#define SED "sed" /* The name of the 'sed' program */
- X#define TEST "if test" /* Leader for test types */
- X
- X/*
- X * This is a small routine that given the beginning of a quoted, backslashed
- X * or just plain string, will return it in a given buffer.
- X */
- Xvoid
- Xcopystring(source, dest)
- Xchar *source, *dest;
- X{
- X register int i = 0;
- X char c;
- X
- X if ('\'' == *source || '\"' == *source) {/* Is it a quoted string? */
- X c = *source;
- X while (c != *++source)
- X dest[i++] = *source;
- X source++;
- X } else if ('\\' == *source) { /* Is it a backslashed string? */
- X while (!isspace(*++source))
- X dest[i++] = *source;
- X } else { /* Just a string */
- X while (!isspace(*source)) {
- X dest[i++] = *source;
- X source++;
- X }
- X }
- X dest[i] = '\0';
- X}
- X
- Xvoid
- Xwordcount(buf, filename, wc)
- Xchar *buf, *filename;
- Xint wc;
- X{
- X if (wc != atoi(buf)) {
- X (void) printf("Error unsharing %s (wc should have been %d, but was %d)\n", filename, atoi(buf), wc);
- X }
- X}
- X
- Xint
- Xcheckfile(string)
- Xchar *string;
- X{
- X char filename[BUFSIZE];
- X
- X while (0 != isspace(*string))
- X string++;
- X
- X copystring(string, filename);
- X if (0 == access(filename, F_OK))
- X return 1;
- X
- X return 0;
- X}
- X
- X/*
- X * This is a small routine that given a 'cat' or 'sed' string, will pull out
- X * the end of file string and the file name
- X */
- Xvoid
- Xgetendfile(line, end, file)
- Xchar *line, /* The 'sed' or 'cat' string */
- X *end, /* Place to store the end of file marker */
- X *file; /* Place for the filename */
- X{
- X char *tmp;
- X
- X /*
- X * This section of code finds the end of file string. It assumes
- X * that the eof string is the string of characters immediately
- X * following the last '<' and that it has either a '\' preceding it
- X * or is surrounded by single quotes.
- X */
- X tmp = (char *) strrchr(line, '<'); /* Find the last '<' on the
- X * line */
- X while (isspace(*++tmp))
- X ; /* Do nothing */
- X copystring(tmp, end);
- X
- X /*
- X * This section of code finds the name of the file. It assumes that
- X * the name of the file is the string immediately following the last
- X * '>' in the line
- X */
- X tmp = (char *) strrchr(line, '>');
- X while (isspace(*++tmp))
- X ; /* Do Nothing */
- X copystring(tmp, file);
- X
- X#ifdef DEBUG
- X (void) printf("EOF = %s, FILE = %s\n", end, file);
- X#endif DEBUG
- X}
- X
- Xint
- Xmain(argc, argv)
- Xint argc;
- Xchar **argv;
- X{
- X FILE *fp, *dfp; /* input file pointer and dest file
- X * pointer */
- X char buf[BUFSIZE], /* line buffer */
- X prefix[STRLEN], /* SED leader if any */
- X endstring[STRLEN], /* EOF marker */
- X filename[STRLEN]; /* file name */
- X int infile = 0, /* var to tell if we're in the middle of a
- X * file or not */
- X wc = 0, /* variable to keep a word count */
- X fileexists = 0; /* does the file exist? */
- X
- X if (1 == argc) { /* check usage */
- X (void) printf("usage: unshar <file>");
- X }
- X if (NULL == (fp = fopen(argv[1], "r"))) {
- X (void) printf("Error opening input file\n");
- X exit(1);
- X }
- X while (NULL != fgets(buf, BUFSIZE, fp)) { /* while there are lines
- X * to get */
- X#ifdef DEBUG
- X puts(buf);
- X#endif DEBUG
- X
- X if (0 == infile) { /* if we are not in the middle of a
- X * file */
- X if ('#' == buf[0]) /* comment? */
- X continue;
- X
- X /* Is this a CAT type shar? */
- X if (0 == strncmp(buf, CAT, strlen(CAT))) {
- X prefix[0] = '\0';
- X getendfile(buf, endstring, filename);
- X if (fileexists != 0) {
- X fprintf(stderr, "File exists (%s), skipping\n", filename);
- X fileexists = 0;
- X continue;
- X }
- X if (NULL == (dfp = fopen(filename, "w"))) {
- X (void) printf("Error opening output file %s\n", filename);
- X exit(1);
- X }
- X (void) printf("Extracting %s ... ", filename);
- X (void) fflush(stdout);
- X infile = 1;
- X wc = 0;
- X continue;
- X }
- X /* Is it a SED type shar? */
- X if (0 == strncmp(buf, SED, strlen(SED))) {
- X register int i = 0, j = 0;
- X
- X while ('^' != buf[i++])
- X ;
- X while ('/' != buf[i]) {
- X prefix[j++] = buf[i++];
- X }
- X prefix[j] = '\0';
- X getendfile(&buf[i], endstring, filename);
- X if (fileexists != 0) {
- X fprintf(stderr, "File exists (%s), skipping\n", filename);
- X fileexists = 0;
- X continue;
- X }
- X if (NULL == (dfp = fopen(filename, "w"))) {
- X (void) printf("Error opening output file %s\n", filename);
- X exit(1);
- X }
- X (void) printf("Extracting %s ... ", filename);
- X (void) fflush(stdout);
- X infile = 1;
- X wc = 0;
- X continue;
- X }
- X /* Do we want to do a test of sorts on a file? */
- X if (0 == strncmp(buf, TEST, strlen(TEST))) {
- X register int i = 0;
- X
- X while(!isdigit(buf[i]) && buf[i] != '-' && buf[i])
- X i++;
- X
- X if (0 != isdigit(buf[i])) {
- X wordcount(&buf[i], filename, wc);
- X }
- X
- X if ('f' == buf[++i]) {
- X fileexists = checkfile(&buf[++i]);
- X }
- X continue;
- X }
- X } else { /* We are in the middle of a file */
- X
- X /* Are we at the end of this one? */
- X if (0 == strncmp(buf, endstring, strlen(endstring))) {
- X (void) printf("Done\n");
- X (void) fclose(dfp);
- X infile = 0;
- X continue;
- X }
- X /* No, then does it have a prefix? */
- X if ('\0' == prefix[0]) {
- X fputs(buf, dfp);
- X wc = wc + strlen(buf);
- X } else {
- X
- X /*
- X * If it does have a prefix, is there one on
- X * this line?
- X */
- X if (0 != strncmp(buf, prefix, strlen(prefix))) {
- X fputs(buf, dfp);
- X } else {
- X fputs(&buf[strlen(prefix)], dfp);
- X wc = wc + strlen(buf) - strlen(prefix);
- X }
- X }
- X }
- X }
- X (void) printf("All Done!\n");
- X (void) fclose(fp);
- X}
- END_OF_FILE
- if test 6759 -ne `wc -c <'uucp2/src/unix/unshar.c'`; then
- echo shar: \"'uucp2/src/unix/unshar.c'\" unpacked with wrong size!
- fi
- # end of 'uucp2/src/unix/unshar.c'
- fi
- echo shar: End of archive 5 \(of 12\).
- cp /dev/null ark5isdone
- MISSING=""
- for I in 1 2 3 4 5 6 7 8 9 10 11 12 ; do
- if test ! -f ark${I}isdone ; then
- MISSING="${MISSING} ${I}"
- fi
- done
- if test "${MISSING}" = "" ; then
- echo You have unpacked all 12 archives.
- rm -f ark[1-9]isdone ark[1-9][0-9]isdone
- else
- echo You still need to unpack the following archives:
- echo " " ${MISSING}
- fi
- ## End of shell archive.
- exit 0
- --
- Mail submissions (sources or binaries) to <amiga@cs.odu.edu>.
- Mail comments to the moderator at <amiga-request@cs.odu.edu>.
- Post requests for sources, and general discussion to comp.sys.amiga.
-